package org.syh.boyangfighthealthclub.controller;

import org.syh.boyangfighthealthclub.entity.Book;
import org.syh.boyangfighthealthclub.service.IBookService;
import org.syh.boyangfighthealthclub.service.impl.BookServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author: Ben
 * @Date: 2021/3/13 19:21
 */
@WebServlet("/admin/updateBook")
public class UpdateBook extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;utf-8");
        Integer id=Integer.parseInt(req.getParameter("id"));
        String bookName=req.getParameter("bookName");
        String publishName=req.getParameter("publishName");
        String author=req.getParameter("author");
        String bookDescription=req.getParameter("bookDescription");
        String isBorrow=req.getParameter("isBorrow");
        if ("".equals(bookName)||"".equals(publishName)||"".equals(author)||"".equals(bookDescription)||"".equals(isBorrow)){
            resp.sendRedirect("../failBook.jsp");
        }
        IBookService iBookService=new BookServiceImpl();
        boolean judgment=iBookService.updateBook(new Book(id,bookName,publishName,author,bookDescription,isBorrow));
        if (judgment){
            resp.sendRedirect("../successBook.jsp");
        }
    }
}
